﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AirlineBooking.Models.DTO
{
    public class DTOFlightStatus
    {
        static DTOFlightStatus(){
            using (AirLineDBModelEntities db = new AirLineDBModelEntities())
            {
                AirlineBooking.FlightStatu t = db.FlightStatus.FirstOrDefault(i => i.Status == "Available");
                Available = t != null ? new DTOFlightStatus(t) : null;
                t = db.FlightStatus.FirstOrDefault(i => i.Status == "Cancelled");
                Cancelled = t != null ? new DTOFlightStatus(t) : null;
                t = db.FlightStatus.FirstOrDefault(i => i.Status == "Delayed");
                Delayed = t != null ? new DTOFlightStatus(t) : null;
                t = db.FlightStatus.FirstOrDefault(i => i.Status == "Departed");
                Departed = t != null ? new DTOFlightStatus(t) : null;
                t = db.FlightStatus.FirstOrDefault(i => i.Status == "Arrived");
                Arrived = t != null ? new DTOFlightStatus(t) : null;
            }
        }

        private DTOFlightStatus(int id, string value)
        {
            Id = id;
            Value = value;
        }

        private DTOFlightStatus(AirlineBooking.FlightStatu status)
            : this(status.Id, status.Status)
        {
        }
        public string Value { get; set; }
        public int Id { get; set; }
        public static readonly DTOFlightStatus Available;
        public static readonly DTOFlightStatus Cancelled;
        public static readonly DTOFlightStatus Delayed;
        public static readonly DTOFlightStatus Departed;
        public static readonly DTOFlightStatus Arrived;
    }
}